home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / tl / tu-comment.el.z / tu-comment.el
Encoding:
Text File  |  1998-05-21  |  4.1 KB  |  129 lines

  1. ;;; tu-comment.el --- a comment out utility for Lisp programs.
  2.  
  3. ;; Copyright (C) 1995,1996 MORIOKA Tomohiko
  4.  
  5. ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
  6. ;; Created: 1995/10/27
  7. ;; Version: $Id: tu-comment.el,v 4.0 1996/09/02 12:58:05 morioka Exp $
  8. ;; Keywords: comment, Lisp
  9.  
  10. ;; This file is part of tl (Tiny Library).
  11.  
  12. ;; This program is free software; you can redistribute it and/or
  13. ;; modify it under the terms of the GNU General Public License as
  14. ;; published by the Free Software Foundation; either version 2, or (at
  15. ;; your option) any later version.
  16.  
  17. ;; This program is distributed in the hope that it will be useful, but
  18. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20. ;; General Public License for more details.
  21.  
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with this program; see the file COPYING.  If not, write to
  24. ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  25. ;; Boston, MA 02111-1307, USA.
  26.  
  27. ;;; Commentary:
  28.  
  29. ;; - How to install.
  30. ;;   1. bytecompile this file and copy it to the apropriate directory.
  31. ;;   2. put the following lines to your ~/.emacs:
  32. ;;        (autoload 'comment-sexp "tu-comment" nil t)
  33. ;;        (global-set-key "\C-c\C-q" 'comment-sexp)
  34. ;; - How to use.
  35. ;;      type `C-c C-q' at the beginning of S-expression you want to
  36. ;;      comment out.
  37.  
  38. ;;; Code:
  39.  
  40. (defvar comment-sexp-first-line-method-alist
  41.   '((emacs-lisp-mode       . comment-sexp-middle-line-method-for-lisp)
  42.     (lisp-interaction-mode . comment-sexp-middle-line-method-for-lisp)
  43.     (lisp-mode             . comment-sexp-middle-line-method-for-lisp)
  44.     (scheme-mode           . comment-sexp-middle-line-method-for-lisp)
  45.     (c-mode                . comment-sexp-first-line-method-for-c)
  46.     (c++-mode              . comment-sexp-middle-line-method-for-c++)
  47.     ))
  48.  
  49. (defvar comment-sexp-middle-line-method-alist
  50.   '((emacs-lisp-mode       . comment-sexp-middle-line-method-for-lisp)
  51.     (lisp-interaction-mode . comment-sexp-middle-line-method-for-lisp)
  52.     (lisp-mode             . comment-sexp-middle-line-method-for-lisp)
  53.     (scheme-mode           . comment-sexp-middle-line-method-for-lisp)
  54.     (c-mode                . comment-sexp-middle-line-method-for-c)
  55.     (c++-mode              . comment-sexp-middle-line-method-for-c++)
  56.     ))
  57.  
  58. (defvar comment-sexp-last-line-method-alist
  59.   '((emacs-lisp-mode       . comment-sexp-last-line-method-for-dummy)
  60.     (lisp-interaction-mode . comment-sexp-last-line-method-for-dummy)
  61.     (lisp-mode             . comment-sexp-last-line-method-for-dummy)
  62.     (scheme-mode           . comment-sexp-last-line-method-for-dummy)
  63.     (c-mode                . comment-sexp-last-line-method-for-c)
  64.     (c++-mode              . comment-sexp-last-line-method-for-dummy)
  65.     ))
  66.  
  67. (defun comment-sexp-middle-line-method-for-lisp ()
  68.   (insert ";; ")
  69.   )
  70.  
  71. (defun comment-sexp-middle-line-method-for-c++ ()
  72.   (insert "// ")
  73.   )
  74.  
  75. (defun comment-sexp-first-line-method-for-c ()
  76.   (insert "/* ")
  77.   )
  78.  
  79. (defun comment-sexp-middle-line-method-for-c ()
  80.   (insert " * ")
  81.   )
  82.  
  83. (defun comment-sexp-last-line-method-for-c (c)
  84.   (insert "\n")
  85.   (while (< 0 c)
  86.     (insert " ")
  87.     (setq c (1- c))
  88.     )
  89.   (insert " */")
  90.   )
  91.  
  92. (defun comment-sexp-last-line-method-for-dummy (c))
  93.  
  94. (defun comment-sexp ()
  95.   (interactive)
  96.   (let ((c (current-column))
  97.         (b (save-excursion
  98.              (beginning-of-line)
  99.              (point)))
  100.         (e (save-excursion
  101.              (forward-sexp)
  102.              (point)
  103.              ))
  104.         )
  105.     (save-excursion
  106.       (save-restriction
  107.         (narrow-to-region b e)
  108.         (untabify b e)
  109.         
  110.         (beginning-of-line)
  111.         (move-to-column c)
  112.         (funcall
  113.          (cdr (assq major-mode comment-sexp-first-line-method-alist)))
  114.         (forward-line)
  115.         
  116.         (while (< (point) (point-max))
  117.           (beginning-of-line)
  118.           (move-to-column c)
  119.           (funcall
  120.            (cdr (assq major-mode comment-sexp-middle-line-method-alist)))
  121.           (forward-line)
  122.           )
  123.         
  124.         (funcall
  125.          (cdr (assq major-mode comment-sexp-last-line-method-alist)) c)
  126.         ))))
  127.  
  128. ;;; tu-comment.el ends here
  129.